home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.csug.rochester.edu!rit!kar
- From: kar@cs.rit.edu (Kenneth A Reek)
- Subject: What's your compiler's answer?
- Message-ID: <1996Feb7.140945.28351@cs.rit.edu>
- Sender: news@cs.rit.edu (USENET News Admin)
- Nntp-Posting-Host: athens
- Organization: Rochester Institute of Technology, Rochester, NY
- Date: Wed, 7 Feb 1996 14:09:45 GMT
-
- In preparing some materials for a course, I wrote the following
- program to illustrate that the order of expression evaluation is not
- determined completely by the precedence of the operators involved. I
- ran it on every compiler I could find and, not surprisingly, got lots of
- different answers.
-
- I'd like to get results from this program for as many different
- compilers as I can to drive home the point that expressions of this
- sort must be avoided. If you have access to a C compiler OTHER THAN
- THE ONES LISTED BELOW, I'd be grateful if you could run this program
- and send me the results. Please include the operating system you are
- using (if appropriate to the identification of the compiler) and the
- compiler version number if it has one.
-
- Thanks for your help. E-mail your results to kar@cs.rit.edu
- I'll post the results if anyone is interested.
-
- - Ken
-
- Here's the program (hold on to your hats):
-
- int main(){
- int i = 10;
-
- i = i-- - --i * ( i = -3 ) * i++ + ++i;
- printf( "i = %d\n", i );
- return 0;
- }
-
- Results found to date:
-
- 21 Borland C/C++ 4.0, Turbo C++ 4.5
- -86 Sun 3/50 cc
- -85 Sun Sparc cc, SunOS 4.1.4 (a K&R compiler)
- 4 Sun Sparc acc, SunOS 4.1.4 (an ANSI compiler)
- 36 DEC VAX/VMS
- 21 Silicon Graphics Indy, IRIX 5.3
- -63 gcc 2.6.3
- --
- Kenneth A. Reek kar@cs.rit.edu
- Rochester Institute of Technology 716-475-6155 (voice)
- Rochester, NY 14623-0887 USA 716-475-7100 (fax)
-